package com.xyy.saas.payment.config;

import com.google.common.base.Preconditions;
import com.pingplusplus.Pingpp;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: wuqiongda
 * @Date: 2019/10/24 19:07
 */
@Component
public class PingxxConfig implements InitializingBean {

    @Value("${pingxx.privateKey}")
    private String privateKey;

    @Value("${pingxx.apiKey}")
    private String apiKey;

    @Value("${pingxx.apiBase}")
    private String apiBase;

    @Value("${pingxx.publicKey}")
    private String publicKey;
    public static Map<String, String> professionMap = new HashMap<>();
    public static Map<String, String> industryMap = new HashMap<>();
    static {
        professionMap.put("01","10000");
        professionMap.put("02","20000");
        professionMap.put("03","30000");
        professionMap.put("04","40000");
        professionMap.put("05","50000");
        professionMap.put("06","60000");
        professionMap.put("07","70000");
        professionMap.put("08","80000");

        industryMap.put("101","A");
        industryMap.put("102","C");
        industryMap.put("103","F");
        industryMap.put("104","G");
        industryMap.put("105","H");
        industryMap.put("106","I");
        industryMap.put("107","O");
        industryMap.put("108","P");
        industryMap.put("109","Q");
        industryMap.put("110","S");
        industryMap.put("111","X");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        Preconditions.checkArgument(!StringUtils.isEmpty(apiKey));
        Preconditions.checkArgument(!StringUtils.isEmpty(privateKey));
        Preconditions.checkArgument(!StringUtils.isEmpty(apiBase));
        Pingpp.privateKey = privateKey;
        Pingpp.apiKey = apiKey;
        Pingpp.overrideApiBase(apiBase);
    }

    public String getPingxxPublicKey() {
        return publicKey;
    }
}
